package cmd

import (
	"dockertools/dockerdemo"
	"fmt"
	"github.com/spf13/cobra"
	"os"
)

var (
	loadpath string
)

var loadCmd = &cobra.Command{
	Use:   "load",
	Short: "通过调用 DockerServer API 实现镜像导入",
	Long: `用于 Docker 镜像导入，支持文件、目录方式传入
				dockertools.exe load -l "./images" -a "172.16.66.101:2375"`,
	Run: func(cmd *cobra.Command, args []string) {
		mydocker := dockerdemo.DockerType{HostString: address}

		cli, err := mydocker.InitClient()
		if err != nil {
			fmt.Println(err)
			os.Exit(3)
		}

		mydocker.LoadDirImage(cli, loadpath)
	},
}

func init() {
	rootCmd.AddCommand(loadCmd)
	loadCmd.Flags().StringVarP(&address, "address", "a", "",
		"用于指定当前连接的远程主机的地址，为空即使用本地的 Docker 连接")
	loadCmd.Flags().StringVarP(&loadpath, "loadpath", "l", "",
		"用于指定用于导入镜像的目录，默认为空")
}
